package cn.edu.ujn.lab3.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;

import cn.edu.ujn.lab3.dao.Product;
import cn.edu.ujn.lab3.dao.ProductMapper;
import cn.edu.ujn.lab3.utils.Page;


@Service("productService")
@Transactional
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductMapper productDao;
	
	@Override
	public int deleteByPrimaryKey(Integer id) {
		int deleteByPrimaryKey = productDao.deleteByPrimaryKey(id);
		return deleteByPrimaryKey;
	}

	@Override
	public int insert(Product row) {
		int insert = productDao.insert(row);
		return insert;
	}

	@Override
	public int insertSelective(Product row) {
		int insertSelective = productDao.insertSelective(row);
		return insertSelective;
	}

	@Override
	public Product selectByPrimaryKey(Integer id) {
		Product selectByPrimaryKey = productDao.selectByPrimaryKey(id);
		return selectByPrimaryKey;
	}

	@Override
	public int updateByPrimaryKeySelective(Product row) {
		int updateByPrimaryKeySelective = productDao.updateByPrimaryKeySelective(row);
		return updateByPrimaryKeySelective;
	}

	@Override
	public int updateByPrimaryKey(Product row) {
		int updateByPrimaryKey = productDao.updateByPrimaryKey(row);
		return updateByPrimaryKey;
	}

	@Override
	public List<Product> selectAll() {
		List<Product> selectAll = productDao.selectAll();
		return selectAll;
	}

	@Override
	public List<Product> selectProductList(Product product) {
		List<Product> selectProductList = productDao.selectProductList(product);
		return selectProductList;
	}

	@Override
	public Integer selectProductListCount(Product product) {
		Integer selectProductListCount = productDao.selectProductListCount(product);
		return selectProductListCount;
	}

	@Override
	public Page<Product> findProductList(Integer page, Integer rows, Integer id,String name,Double price) {
		// TODO Auto-generated method stub
		
		Product product=new Product();
		product.setId(id);
		product.setPrice(price);
		product.setName(name);
		product.setStart((page-1) * rows);
		product.setRows(rows);
		List<Product> products=this.productDao.selectProductList(product);
		//查询客户列表总记录数
		Integer count = this.productDao.selectProductListCount(product);
		Page<Product> result=new Page<Product>();
		result.setPage(page);
		result.setRows(products);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

	@Override
	public List<Product> findProductById(Integer id) {
		List<Product> findProductById = productDao.findProductById(id);
		return findProductById;
	}

}
